<?php

namespace App\Admin\Extensions;

use Encore\Admin\Admin;

class AddCash
{
    protected $id;

    public function __construct($sign, $client_url, $potocol, $bsign)
    {
        $this->sign = $sign;
        $this->client_url = $client_url;
        $this->protocol = $potocol;
        $this->bsign = $bsign;
    }

    protected function script()
    {
        return <<<SCRIPT

layui.use('layer', function(){
        var layer = layui.layer;
        $('.dispay').click(function () {
           var that = this;
           var sign = $(that).attr('data-sign');
           var client_url = $(that).attr('data-clienturl');
           var protocol = $(that).attr('data-protocol');
           layer.prompt(function(value, index, elem){
                var reg=/^[0-9]+.?[0-9]*$/;
                if(!reg.test(value)){
                    alert('格式不正确，请重新输入！');
                    return;
                }
                $.ajax({
                    url: '/admin/handpay',
                    type: 'post',
                    data: {
                        sign: sign,
                        client_url: client_url,
                        cash: value,
                        protocol: protocol
                    },
                    success: function(res){
                        layer.msg(res.info);
                    }
                });
                layer.close(index);
           });
       });
       
       $('.discount').click(function(){
            var sign = $(this).attr('data-sign');
            var bsign = $(this).attr('data-bsign');
            $.ajax({
                url: '/admin/clients/deduct?sign='+sign,
                type: 'get',
                success: function(res){
                    if(res.code){
                        var html = '<\div class="main" style="width: 500px;margin-top: 10px;;">';
                        html += '<\div style="height: 33px;;"><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">实名认<\/span><\input value="'+res.verify+'" style="width:50%;margin-right: 40px;" type="text" name="verify"><\/div>';
                        
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">银行卡认证<\/span><\input value="'+res.bindcard+'"  style="width:50%;margin-right: 40px;"  type="text" name="bindcard"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">置信分<\/span><\input value="'+res.sort+'"  style="width:50%;margin-right: 40px;"  type="text" name="sort"><\/div>';
//                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">手机认证<\/span><\input value="'+res.moxie+'"  style="width:50%;margin-right: 40px;"  type="text" name="moxie"><\/div>';
//                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">淘宝认证<\/span><\input value="'+res.taobaoweb+'"  style="width:50%;margin-right: 40px;"  type="text" name="taobaoweb"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">短信<\/span><\input value="'+res.message+'"  style="width:50%;margin-right: 40px;"  type="text" name="message"><\/div>';
//                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">全景雷达<\/span><\input value="'+res.rada+'"  style="width:50%;margin-right: 40px;"  type="text" name="rada"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">准入分<\/span><\input value="'+res.bairong+'"  style="width:50%;margin-right: 40px;"  type="text" name="bairong"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">反欺诈报告<\/span><\input value="'+res.fraud+'"  style="width:50%;margin-right: 40px;"  type="text" name="fraud"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">运营商<\/span><\input value="'+res.carrier+'"  style="width:50%;margin-right: 40px;"  type="text" name="carrier"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">多头查询<\/span><\input value="'+res.duotou+'"  style="width:50%;margin-right: 40px;"  type="text" name="duotou"><\/div>';
                        html += '<\/div>';
                    }else if(!res.code){
                        var html = '<\div class="main" style="width: 500px;margin-top: 10px;;">';
                        html += '<\div style="height: 33px;;"><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">实名认<\/span><\input value="0" style="width:50%;margin-right: 40px;" type="text" name="verify"><\/div>';
                       
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">银行卡认证<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="bindcard"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">置信分<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="sort"><\/div>';
//                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">手机认证<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="moxie"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">淘宝认证<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="taobaoweb"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">短信<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="message"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">全景雷达<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="rada"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">准入分<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="bairong"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">反欺诈报告<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="fraud"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">运营商<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="carrier"><\/div>';
                        html += '<\div style="height: 33px;" ><\span style="display: inline-block;width: 24%;height: 1.7em;margin-left: 40px;">多头查询<\/span><\input value="0"  style="width:50%;margin-right: 40px;"  type="text" name="duotou"><\/div>';
                        html += '<\/div>';
                    }
                    layer.open({
                        type: 1,
                        content: html,
                        area: ['500px'],
                        btn: ['确定'],
                        yes: function(){
                            var verify = $('input[name=verify]').val();
                            var bindcard = $('input[name=bindcard]').val();
                            var sort = $('input[name=sort]').val();
//                            var moxie = $('input[name=moxie]').val();
//                            var taobaoweb = $('input[name=taobaoweb]').val();
                            var message = $('input[name=message]').val();
//                            var rada = $('input[name=rada]').val();
                            var bairong = $('input[name=bairong]').val();
                            var fraud = $('input[name=fraud]').val();
                            var carrier = $('input[name=carrier]').val();
                            var duotou = $('input[name=duotou]').val();
                            var reg=/^[0-9]+.?[0-9]*$/;
                            if(!reg.test(verify) || !reg.test(bindcard) || !reg.test(sort) || !reg.test(message) || !reg.test(bairong) || !reg.test(duotou)){
                                alert('格式不正确，请输入数字！');
                                return;
                            }
                            $.ajax({
                                url: '/admin/clients/deduct',
                                type: 'post',
                                data: {
                                    verify: verify,
                                    bindcard: bindcard,
                                    sort: sort,
                                    moxie: 1,
                                    taobaoweb: 1,
                                    message: message,
                                    rada: 1,
                                    bairong: bairong,
                                    sign: sign,
                                    bsign: bsign,
                                    fraud: fraud,
                                    carrier: carrier,
                                    duotou: duotou,
                                },
                                success: function(res){
                                    layer.msg(res.info);
                                }
                            });
                        }
                    });
                }
            });
       });
       $('.zhidetail').click(function(){
           var sign = $(this).attr('data-sign');
           layer.open({
                type: 2,
                content: '/admin/clients/detail/show?sign='+sign,
                area: ['80%', '200px']
           });
       });
       
});
SCRIPT;
    }

    protected function render()
    {
        Admin::script($this->script());

        return "<a class='btn dispay btn-xs btn-success fa grid-check-row' data-protocol='{$this->protocol}' data-clienturl='{$this->client_url}' data-sign='{$this->sign}'>手充</a>
                <a data-sign='{$this->sign}' data-bsign='{$this->bsign}' class='btn discount btn-xs btn-warning fa grid-check-row'>扣费</a>
                <a data-sign='{$this->sign}' class='btn zhidetail btn-xs btn-primary fa grid-check-row'>祥情</a>";
    }

    public function __toString()
    {
        return $this->render();
    }
}